/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.system;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.system.SystemUser;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class UserTM extends AbstractTableModel{
    private List<SystemUser> data;

    public UserTM() {
        this (new ArrayList<SystemUser>(0));
    }

    public UserTM(List<SystemUser> data) {
        this.data = data;
    }

    public SystemUser get(int index) {
        return data.get(index);
    }

    public void add(SystemUser product) {
        data.add(product);
        fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
    }

    public void remove(int index) {
        data.remove(index);
        fireTableRowsDeleted(index, index);
    }

    public void set(int index, SystemUser product) {
        data.set(index, product);
        fireTableRowsUpdated(index, index);
    }

    public void clear() {
        data.clear();
        fireTableDataChanged();
    }

    public void add(Collection<SystemUser> products) {
        data.addAll(products);
        fireTableRowsInserted(getRowCount() - (products.size()), getRowCount() - 1);
    }
    
    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return 8;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
         switch (columnIndex) {
            case 0: return rowIndex+1;
            case 1: return data.get(rowIndex).getUserName();
            case 2: return data.get(rowIndex).getFullName();
       //     case 3: return data.get(rowIndex).getPasswd();
            case 3: return data.get(rowIndex).getSystemGroup().getGroupName();
            case 4: return data.get(rowIndex).getPhone();            
            case 5: return data.get(rowIndex).getSuspended();//(data.get(rowIndex).getSuspended()!=null?(data.get(rowIndex).getSuspended()?"Tidak Aktif":"Aktif"):"");
            case 6: return data.get(rowIndex).getUserId();
            default: return null;
        }
    }
    
    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0: return "NO";
            case 1: return "USER NAME";
            case 2: return "FULLNAME";
            case 3: return "GROUP";
            case 4: return "PHONE";
            case 5: return "NON AKTIF";                        
            case 6: return "ID";
            default: return null;
        }
    }
    
    @Override
    public Class getColumnClass(int c) {
            //return getValueAt(0, c).getClass();
        Object value=this.getValueAt(0,c);  
        return (value==null?Object.class:value.getClass());  
    }
}
